<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">

<title>登录页面</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="css/login.css" />

</head>

<body class="beg-login-bg">
	<div class="beg-login-box">
		<header>
			<h1>后台登录</h1>
		</header>
		<div class="beg-login-main">
			<form class="layui-form" method="post">
				<div class="layui-form-item">
					<label class="beg-login-icon"> <i class="layui-icon">&#xe612;</i>
					</label> <input type="text" id="userName" lay-verify="userName"
						autocomplete="off" placeholder="这里输入登录名" class="layui-input">
				</div>
				<div class="layui-form-item">
					<label class="beg-login-icon"> <i class="layui-icon">&#xe642;</i>
					</label> <input type="password" id="password" lay-verify="password"
						autocomplete="off" placeholder="这里输入密码" class="layui-input">
				</div>
				<div class="layui-form-item">
					<div class="beg-pull-left beg-login-remember">
						<label>记住帐号？</label> <input type="checkbox" name="rememberMe"
							value="true" lay-skin="switch" checked title="记住帐号">
					</div>
					<div class="beg-pull-right">
						<button class="layui-btn  layui-btn-normal" lay-submit
							lay-filter="login" id="login">
							<i class="layui-icon">&#xe650;</i> 登录
						</button>
					</div>
					<div class="beg-clear"></div>
				</div>
			</form>
		</div>
		<footer>
			<p>songPC © www.songpengcheng.com</p>
		</footer>
	</div>
	<script type="text/javascript" src="plugins/layui/layui.js"></script>
	<script src="js/base/jquery-1.8.2.min.js" type="text/javascript" charset="utf-8"></script>
		<script>
		layui.use([ 'layer', 'form' ], function() {
			var layer = layui.layer, $ = layui.jquery, form = layui.form();
/* 
			form.on('submit(login)', function(data) {

				/* 				location.href = 'index.jsp';
				return false;  // 阻止表单提交 */
				
			});  //这种提交会跳转页面 */
			
			$().ready(function () {
				 
				$('#login').click(function () {   
			        if($.trim($('#userName').val()) == '' || $.trim($('#password').val()) == ''){
/* 			        	layer.msg('账户或密码不能为空！', {icon: 2}); */
			        	layer.msg('账户或密码不能为空！', {offset: '20px'});
			        	 return false;
			        }
					$.ajax({	
			                    type: "POST",
			                    url: "login.action",
			                    data: "sysUser.userName=" + escape($('#userName').val()) + "&sysUser.password=" + escape($('#password').val()),
			                    success: function (msg) {
			                        var data = JSON.parse(msg);
			                    	if (data.success == "true") {
			                            parent.document.location.href = "index.jsp"; //如果登录成功则跳到管理界面
			                        }
			                        if (data.success == "false") {
			                            $('#username').val("");
			                            $('#password').val("");
			                            layer.alert('用户名或密码错误！', {icon: 2});
			                        }
			                    },
			                    error: function () {
			                    	alert('模块加载异常！');
			                    }
			                });
			                return false;
			        });
		});
	</script>
</body>